if exists (select 1
            from  sysobjects
           where  id = object_id('bd_sys_costcenter')
            and   type = 'U')
   drop table bd_sys_costcenter
go

/*==============================================================*/
/* Table: bd_sys_costcenter                                     */
/*==============================================================*/
create table bd_sys_costcenter (
   id                   int                  not null,
   bh                   varchar(10)          not null,
   costcenter_name       varchar(50)          not null,
   dept_ot_max          int                  not null default 0,
   constraint PK_BD_SYS_COSTCENTER primary key (id)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('bd_sys_costcenter') and minor_id = 0)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_sys_costcenter'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '系统设置-成本中心表',
   'user', @CurrentUser, 'table', 'bd_sys_costcenter'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_sys_costcenter')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_sys_costcenter', 'column', 'id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   'ID',
   'user', @CurrentUser, 'table', 'bd_sys_costcenter', 'column', 'id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_sys_costcenter')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'bh')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_sys_costcenter', 'column', 'bh'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '编号',
   'user', @CurrentUser, 'table', 'bd_sys_costcenter', 'column', 'bh'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_sys_costcenter')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'costcenterName')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_sys_costcenter', 'column', 'costcenterName'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '成本中心名称',
   'user', @CurrentUser, 'table', 'bd_sys_costcenter', 'column', 'costcenterName'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_sys_costcenter')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'dept_ot_max')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_sys_costcenter', 'column', 'dept_ot_max'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '部门加班阈值',
   'user', @CurrentUser, 'table', 'bd_sys_costcenter', 'column', 'dept_ot_max'
go
